package com.ruoyi.tcsp.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.tcsp.domain.mysql.TcspBaseFile;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.tcsp.service.ITcspBaseFileService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 文件下载专区文件Controller
 * 
 * @author ruoyi
 * @date 2025-04-20
 */
@RestController
@RequestMapping("/tcsp/fileDown")
public class TcspBaseFileController extends BaseController
{
    @Autowired
    private ITcspBaseFileService tcspBaseFileService;

    /**
     * 查询文件下载专区文件列表
     */
    @PreAuthorize("@ss.hasPermi('tcsp:file:list')")
    @GetMapping("/list")
    public TableDataInfo list(TcspBaseFile tcspBaseFile)
    {
        startPage();
        List<TcspBaseFile> list = tcspBaseFileService.selectTcspBaseFileList(tcspBaseFile);
        return getDataTable(list);
    }

    /**
     * 导出文件下载专区文件列表
     */
    @PreAuthorize("@ss.hasPermi('tcsp:file:export')")
    @Log(title = "文件下载专区文件", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TcspBaseFile tcspBaseFile)
    {
        List<TcspBaseFile> list = tcspBaseFileService.selectTcspBaseFileList(tcspBaseFile);
        ExcelUtil<TcspBaseFile> util = new ExcelUtil<TcspBaseFile>(TcspBaseFile.class);
        util.exportExcel(response, list, "文件下载专区文件数据");
    }

    /**
     * 获取文件下载专区文件详细信息
     */
    @PreAuthorize("@ss.hasPermi('tcsp:file:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tcspBaseFileService.selectTcspBaseFileById(id));
    }

    /**
     * 新增文件下载专区文件
     */
    @PreAuthorize("@ss.hasPermi('tcsp:file:add')")
    @Log(title = "文件下载专区文件", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TcspBaseFile tcspBaseFile)
    {
        LoginUser loginUser = getLoginUser();
        return toAjax(tcspBaseFileService.insertTcspBaseFile(tcspBaseFile, loginUser));
    }

    /**
     * 修改文件下载专区文件
     */
    @PreAuthorize("@ss.hasPermi('tcsp:file:edit')")
    @Log(title = "文件下载专区文件", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TcspBaseFile tcspBaseFile)
    {
        return toAjax(tcspBaseFileService.updateTcspBaseFile(tcspBaseFile));
    }

    /**
     * 删除文件下载专区文件
     */
    @PreAuthorize("@ss.hasPermi('tcsp:file:remove')")
    @Log(title = "文件下载专区文件", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tcspBaseFileService.deleteTcspBaseFileByIds(ids));
    }
}
